cmake_minimum_required(VERSION 3.10)
project(ModernOpenGLExample)

# Set the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Set include directories
include_directories(${CMAKE_SOURCE_DIR}/include)

# Find OpenGL package
find_package(OpenGL REQUIRED)

# Find GLFW package
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLFW REQUIRED glfw3)

# Set GLFW include directories
include_directories(${GLFW_INCLUDE_DIRS})

# Define common source files
set(COMMON_SOURCES src/glad.c)

# Define executable sources
set(EXECUTABLES
    InAndOut:1.InAndOut_输入和输出.cpp
    Uniform:2.Uniform.cpp
    OtherAttr:3.OtherAttr_更多属性.cpp
)

# Create executables and link libraries
foreach(EXECUTABLE_DEFINITION ${EXECUTABLES})
    # Split the definition into target name and source file
    string(REPLACE ":" ";" EXECUTABLE_PARTS ${EXECUTABLE_DEFINITION})
    list(GET EXECUTABLE_PARTS 0 TARGET_NAME)
    list(GET EXECUTABLE_PARTS 1 SOURCE_FILE)
    
    # Add executable
    add_executable(${TARGET_NAME} ${SOURCE_FILE} ${COMMON_SOURCES})
    
    # Link libraries
    target_link_libraries(${TARGET_NAME} OpenGL::GL ${GLFW_LIBRARIES} dl)
endforeach()

# Add executable
add_executable(ReadFromFile 4.ReadFromFile_从文件读取.cpp Shader.cpp src/glad.c)

# Link libraries
target_link_libraries(ReadFromFile OpenGL::GL ${GLFW_LIBRARIES} dl)

# Add executable
add_executable(UniformShift exe2.UniformShift.cpp Shader.cpp src/glad.c)

# Link libraries
target_link_libraries(UniformShift OpenGL::GL ${GLFW_LIBRARIES} dl)